﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Settle_Exchange.aspx.cs" Inherits="Web.Settle.Settle_Exchange" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script src="../Scripts/WebInner.js" type="text/javascript"></script>
    <script src="../Scripts/Common.js" type="text/javascript"></script>
    <link href="../Styles/Common.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/Zebra/zebra_dialog.js" type="text/javascript"></script>
    <link href="../Scripts/Zebra/zebra_dialog.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../Lodop6.198/LodopFuncs.js" type="text/javascript"></script>
      <script type="text/javascript">
          /*--------窗体启动设置和基本设置--------*/
          /*--loadFuntion--*/
          $(function () {

              InitWBID();
              $('#QWBID').change(function () {
                  if ($('#QWBID option:selected').val() != "") {
                      $('#txtWBID').val($('#QWBID option:selected').text());
                  }
              });
              GetAccountant();//获取总部会计信息

          });
          function InitWBID() {
              var WBName = $.trim($('#txtWBID').val());
              $('#QWBID').empty();
              $.ajax({
                  url: '/Ashx/wbinfo.ashx?type=GetWBByName&strName=' + WBName,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      if (WBName == '') {
                          $('#QWBID').append("<option value=''>--请选择--</option>");
                      }
                      if (r.responseText == "Error") { return false; }
                      for (var i = 0; i < r.length; i++) {
                          $('#QWBID').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                      }

                  }, error: function (r) {

                  }
              });
          }


          function GetAccountant() {
              $.ajax({
                  url: '/Ashx/settlebasic.ashx?type=GetAccountant',
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {
                      //加载网点营业员
                      if (r.length < 1) {
                          $.Zebra_Dialog('<strong>获取总部会计信息失败 ！</strong>');
                          return false;
                      }
                      $('select[name=Accountant]').empty();
                      for (var i = 0; i < r.length; i++) {
                          $('select[name=Accountant]').append("<option value='" + r[i].ID + "'>" + r[i].strName + "</option>");
                      }

                  }, error: function (r) {
                      if (r.reponseText == "Error") {
                          $.Zebra_Dialog('<strong>获取总部会计信息失败 ！</strong>');
                      }
                  }
              });
          }



          //获取单笔代理费的信息
          function GetSettleSingle(obj) {
              //查询当前记录是否已经结算
            

              $.ajax({
                  url: '/Ashx/settle.ashx?type=ISHaveExchange&ID=' + obj,
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                      if (r != '0') {
                          $.Zebra_Dialog('<strong>该笔记录已经结算 ！</strong>');
                          return false;
                      }
                      else {
                          ShowSettleSingle(obj);
                      }
                  }, error: function (r) {

                  }
              });


          }

          //获取单笔的计算记录
          function ShowSettleSingle(obj) {
              $('input[name=ID]').val(obj);
              $('input[name=ISPay]').val('0');
              $('#btnPay').removeAttr('disabled');
              $('#btnPrint').attr('disabled', 'disabled');
              $.ajax({
                  url: '/Ashx/settle.ashx?type=GetExchangeSingle&ID=' + obj,
                  type: 'post',
                  data: '',
                  dataType: 'json',
                  success: function (r) {

                      $('#divfrm').fadeIn('normal'); //显示单笔计算窗口
                      $('#S_strName').html(r[0].DepName);
                      $('#S_StorageDate').html(r[0].dt_Exchange);
                      $('#S_GoodName').html(r[0].GoodName);
                      $('#S_UnitName').html(r[0].UnitName);
                      $('#S_GoodCount').html(r[0].GoodCount);
                      $('#S_GoodPrice').html(r[0].GoodPrice);
                      $('#S_VarietyCount').html(r[0].VarietyCount);
                      var ISReturn = r[0].ISReturn;
                    
                      if (parseInt(ISReturn)== 0) {
                          $('#S_Money_DuiHuan').html(r[0].Money_DuiHuan);
                          $('#S_Money_DuiHuan2').html(r[0].Money_DuiHuan);
                      }
                      else {
                          $('#S_Money_DuiHuan').html('-' + r[0].Money_DuiHuan);
                          $('#S_Money_DuiHuan2').html('-' + r[0].Money_DuiHuan);
                      }
                      $('#S_WBName').html(r[0].WBName);


                  }, error: function (r) {
                      if (r.reponseText == "Error") {
                          $.Zebra_Dialog('<strong>获取代理费信息失败 ！</strong>');
                      }
                  }
              });
          }



          //支付现金
          function FunPay() {
              if (confirm('您确认要结算这笔业务吗？')) {
                  $('input[name=ISPay]').val('1');
                  var ID = $('input[name=ID]').val();
                
                  var Accountant = $('select[name=Accountant] option:selected').text();

                  $.ajax({
                      url: '/Ashx/settle.ashx?type=AddSA_Exchange&ID=' + ID + '&Accountant=' + Accountant,
                      type: 'post',
                      data: $('#form1').serialize(),
                      dataType: 'text',
                      success: function (r) {
                          $.Zebra_Dialog('<strong>结算成功 ！</strong>');
                          $('#btnPay').attr('disabled', 'disabled');
                          $('#btnPrint').removeAttr('disabled');
                      }, error: function (r) {
                          if (r.reponseText == "Error") {
                              $.Zebra_Dialog('<strong>结算失败 ！</strong>');
                          }
                      }
                  });

              }
          }

          //全部结算
          function FunPayAll() {
              if (confirm('您确认要将当前页面中的代理费全部结算吗？')) {
                  var WBName = $('#txtWBID').val();
                  var dtStart = $('#Qdtstart').val();
                  var dtEnd = $('#Qdtend').val();

                  $.ajax({
                      url: '/Ashx/settle.ashx?type=AddSA_ExchangeAll&WBName=' + WBName + '&dtStart=' + dtStart + '&dtEnd=' + dtEnd,
                      type: 'post',
                      data: $('#form1').serialize(),
                      dataType: 'text',
                      success: function (r) {
                          if (r == "Error") {
                              $.Zebra_Dialog('<strong>结算失败 ！</strong>');
                          }
                          else {
                              $.Zebra_Dialog('<strong>全部结算成功 ！</strong>');

                          }
                      }, error: function (r) {
                          $.Zebra_Dialog('<strong>结算失败 ！</strong>');
                      }
                  });

              }
          }

          //关闭窗口
          function CloseFrm() {
             
              $('#divfrm').fadeOut('normal');
          }



          //打印付款单据

          function PrintPageSettle() {
              var ID = $('input[name=ID]').val();
              PrintPage(ID);
          }

          function PrintPage(obj) {

              $.ajax({
                  url: '/Ashx/settle.ashx?type=PrintExchange&ID=' + obj,
                  type: 'post',
                  data: '',
                  dataType: 'text',
                  success: function (r) {
                   
                      $('#divPrintPaper').html('');
                      $('#divPrintPaper').append(r);
                      CreatePage();
                      LODOP.PREVIEW(); //打印存折
                  }, error: function (r) {
                      $.Zebra_Dialog('<strong>加载打印坐标时出现错误 ！</strong>');
                  }
              });

          }

          //小票打印
          function CreatePage() {
              LODOP = getLodop();
              LODOP.PRINT_INIT("小票打印");
              LODOP.SET_PRINT_STYLE("FontSize", 12);
              LODOP.SET_PRINT_STYLE("Bold", 1);
              LODOP.ADD_PRINT_TEXT(0, 0, 0, 0, "打印页面部分内容");

              LODOP.ADD_PRINT_HTM(20, 60, 800, 400, document.getElementById("divPrintPaper").innerHTML);

          };

      </script>
</head>
<body>
 <div id="divPrintPaper" style="width: 640px; font-size: 12px; display: none;">
 </div>
    <form id="form1" runat="server">
    <div class="pageHead">
       <b>网点兑换报表</b>
       <%-- <span id="spanHelp" style="cursor: pointer">帮助</span>--%>
    </div>
    <div id="divHelp"  class="pageHelp">
<span>提示1：各种查询可以独使用，也可以联合使用，但必须保证至少有一项查询条件。</span><br />
<span>提示2：每项查询均为模糊查询条件，为保证查找信息的正确性，请输入完整的查询信息。</span><br />

</div>
    
<div id="storageQuery">

</div>
    <div style="margin: 20px 0px;">
        <div id="Query">
            <span>网点名称:</span>
            <input type="text" id="txtWBID" onkeyup="InitWBID();" style="font-size:16px; width:100px; font-weight:bolder;" runat="server" />
            <select id="QWBID"  runat="server" style="width:100px;"></select> &nbsp;
            <span>起始日期:</span>
            <input type="text" id="Qdtstart" readonly="readonly" onclick="WdatePicker();" style="font-size:16px;width:100px; font-weight:bolder;" runat="server" />&nbsp;
           <span>结束日期:</span>
            <input type="text" id="Qdtend" readonly="readonly" onclick="WdatePicker()" style="font-size:16px;width:100px; font-weight:bolder;" runat="server" />&nbsp;
            


            <asp:ImageButton ID="ImageButton1" ImageUrl="~/images/seach_brown.png" 
                runat="server" onclick="ImageButton1_Click" />&nbsp;&nbsp;
                <input type="button" value="全部结算" onclick="FunPayAll();" style="width:100px; font-weight:bolder; font-size:16px; color:Blue;"  />
            
        </div>
        
        <div id="StorageList" style="margin:20px 0px">
        <asp:Repeater ID="Repeater1" runat="server">
            <HeaderTemplate>
                <table class="tabData" >
                    <tr class="tr_head">
                        <th style="width: 100px; height:20px; text-align: center;">
                            网点
                        </th>
                         <th style="width: 100px; text-align: center;">
                            账号
                        </th>
                        <th style="width: 100px; text-align: center;">
                            储户姓名
                        </th>
                        <th style="width: 100px; text-align: center;">
                           存入日期
                        </th>
                        <th style="width: 100px; text-align: center;">
                            业务类型
                        </th>
                        
                        <th style="width: 100px; text-align: center;">
                           商品名称
                        </th>
                          <th style="width: 80px; text-align: center;">
                            单位
                        </th>
                          <th style="width: 80px; text-align: center;">
                            重量
                        </th>
                          <th style="width: 80px; text-align: center;">
                            单价
                        </th>
                          <th style="width: 80px; text-align: center;">
                            折合原粮
                        </th>
                          <th style="width: 80px; text-align: center;">
                            利息
                        </th>
                         <th style="width: 100px; text-align: center;">
                            折合现金
                        </th>
                          <th style="width: 180px; text-align: center;">
                            操作
                        </th>
                        
                       
                    </tr>
            </HeaderTemplate>
            <ItemTemplate>
                <tr style='background-color: <%#(Container.ItemIndex%2==0)?"#FFFFF;":"#fcf3f4"%>'
                    onmouseover="change_colorOver(this)" onmouseout="change_colorOut(this)">
                   <td style="height:25px;">
                     
                        <%#Eval("WBName")%>
                    </td>
                    <td>
                        <%#Eval("AccountNumber")%>
                    </td>
                    <td>
                        <%#Eval("DepName")%>
                    </td>
                     <td>
                        <%#Eval("dt_Exchange")%>
                    </td>
                    <td>
                        <%#Eval("BusinessName")%>
                    </td>
                   <td>
                        <%#Eval("GoodName")%>
                    </td>
                    <td>
                        <%#Eval("UnitName")%>
                    </td>
                    <td>
                        <%#Eval("GoodCount")%>
                    </td>
                    <td>
                        <%#Eval("GoodPrice")%>
                    </td>
                    <td>
                        <%#Eval("VarietyCount")%>
                    </td>
                    <td>
                        <%#Eval("VarietyInterest")%>
                    </td>
                    <td>
                        <%#GetMoneyExchange(Eval("ISReturn"),Eval("Money_DuiHuan"))%>
                    </td>
                    <td>
                      <%-- <a style="color:Red; font-weight:bold;" href="Settle_AgentFeeDetail.aspx?ID=1">asdf</a>--%>
                      <%#GetOperateInfo(Eval("ID"))%>
                    </td>
                   
                </tr>
            </ItemTemplate>
            <FooterTemplate>
           <tr>
             <td style="height:25px;">

                    
                   <td align="center"  colspan="8">
                    <span style="color:Red; font-weight:bold;"> 兑换商品合计:</span> 
                    </td>
                    <td>
                        <%=VarietyCount%>
                    </td>
                    <td>
                      <%=VarietyInterest%>
                    </td>
                    <td>
                       <%=Money_DuiHuan%>
                    </td>
                  
                    <td>
                       
                    </td>
           </tr>
                <!--底部模板-->
                </table>
                <!--表格结束部分-->
            </FooterTemplate>
        </asp:Repeater>
         
        </div>
       
    </div>

     <div  id="divfrm" class="pageEidt" style="display:none; width:720px; height:320px;">
    <div style="float:right; margin:10px 20px">
     <img src="../../images/winClose.png" alt="关闭窗口"  style="float:right; cursor:pointer;" onclick="CloseFrm()" /></div>    
    <br />
    <div style="clear:both;">
        <table class="tabData" style="margin:10px 0px 10px 20px">
            
            <tr>
             <td align="center" style="width:80px;">储户姓名</td>
              <td align="center" style="width:80px;">存储日期</td>
               <td align="center" style="width:80px;">商品名称</td>
                <td align="center" style="width:80px;">单位</td>
                 <td align="center" style="width:80px;">重量</td>
                  <td align="center" style="width:80px;">单价</td>
                   <td align="center" style="width:80px;">折合原粮</td>
                    <td align="center" style="width:80px;">折合现金</td>
            </tr>
            <tr>
                <td align="center">
                    <span id="S_strName"></span>
                </td>
                <td align="center">
                    <span id="S_StorageDate"></span>
                </td>
                <td align="center">
                    <span id="S_GoodName"></span>
                </td>
                <td align="center">
                    <span id="S_UnitName"></span>
                </td>
                <td align="center">
                    <span id="S_GoodCount"></span>
                </td>
                <td align="center">
                    <span id="S_GoodPrice"></span>
                </td>
                <td align="center">
                    <span id="S_VarietyCount"></span>
                </td>
                <td align="center">
                    <span id="S_Money_DuiHuan">元</span>
                </td>
            </tr>
            </table>
            <table style=" margin:10px 0px 0px 100px">
            <tr>
            <td></td>
            <td><span style="color:Blue; font-size:16px; font-weight:bolder;">与网点结算单笔业务费用</span></td>
           
            </tr>
            <tr>
            <td align="right" style="width:120px;"><span>网点:</span></td>
            <td><span id="S_WBName"></span></td>
            </tr>
             <tr>
           <td align="right"><span>总部会计:</span></td>
            <td><select name="Accountant" style="width:100px;"></select></td>
            </tr>
             <tr>
               <td align="right"><span>应付金额:</span></td>
            <td><span id="S_Money_DuiHuan2" style="font-weight:bolder;"></span>元</td>
            </tr>
            
          
               <tr>
            <td></td>
            <td ><input type="button" id="btnPay" value="支付现金" onclick="FunPay()" />&nbsp;
            <input type="button" id="btnPrint" value="打印凭证" disabled="disabled" onclick="PrintPageSettle()" />
           
             </td>
            </tr>
        </table>
        </div>
    </div>
    
    <div  style="display:none;">
      <%--被选择的存入信息条目--%>
        <input type="text" name="ID" value="" />
     <%--是否已经发生了结算业务  1:发生了 0：未发生--%>
       <input type="text" name="ISPay" value="" />
    </div>
    </form>
    
    <%--定义编号--%>
    <input type="hidden" id="WBID" value="" />
    <%--定义背景色的隐藏域--%>
    <input type="hidden" id="colorName" value="" />
</body>
</html>